<template>
	<view class="mainpadding2">
		<view class="flexcenter" v-if="!list.data.length">
			<view class="placeholderimage" style="margin-top: 300rpx;" ></view>
		</view>
		<view class="xiahuaxian margin_top" v-for="item in list.data" :key="item.id">
			<view class="flexbetween">
				<view class="shilitu">
					<image :src="item.image_text" mode=""></image>
				</view>
				<view class="" style="width: 69%;">
					<view class="titletext xiaohei fonweight yhxk">{{item.name}}</view>
					<view class="strongtext xiaohui nofonweight margin_top2">{{item.kc_des}} </view>
					<view class="flexbetween margin_top2">
						<view class="titletext xiaohong fonweight" v-show="type!=5">¥ {{item.priceinfo.price}}</view>
						<view class="titletext xiaohong fonweight" v-show="type==5">{{item.priceinfo.score}}分<text v-if="Number(item.priceinfo.price)">+¥ {{item.priceinfo.price}}</text></view>
						<view class="xiaohongbtnty" v-show="type == 2" @click="tzxq(2,item.id)">立即秒杀</view>
						<view class="xiaohongbtnty" v-show="type == 3" @click="tzxq(3,item.id)">立即团购</view>
						<view class="xiaohongbtnty" v-show="type == 4" @click="tzxq1(4,item.id)">立即砍价</view>
						<view class="xiaohongbtnty" v-show="type == 5" @click="tzxq(5,item.id)">立即兑换</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				type: "",
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				keywords:"",
				lat:"",
				lng:"",
			}
		},
		onLoad(options) {
			this.type = options.id
			let text = ""
			if (this.type == 2) {
				text = "秒杀"
			} else if (this.type == 3) {
				text = "团购"
			} else if (this.type == 4) {
				text = "砍价"
			} else if (this.type == 5) {
				text = "积分兑换"
			}
			uni.setNavigationBarTitle({
				title: text
			});
			this.init()
		},
		methods: {
			init(isPage, page) {
				let _this = this;
				let data = {
					page: page || 1,
					limit: _this.limit,
					keywords:this.keywords,
					lat: this.lat,
					lng: this.lng,
					kc_attr: this.type,
				}
				let url = '/api/kccl/kcIndex'
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
						this.$forceUpdate()
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			// // 跳转课程详情
			tzxq(type,id) {
				uni.navigateTo({
					url: '/pages_homepage/kechenggmxq?type=' + type+"&id="+id
				})
			},
			tzxq1(type,id) {
				uni.navigateTo({
					url: '/pages_homepage/miaoshakecxq?type=' + type+"&id="+id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.shilitu {
		width: 200rpx;
		height: 160rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>